/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.emailsenderdemo;

import com.mycompany.emailsenderdemo.vo.EmailVO;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.mail.DefaultAuthenticator;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;
import org.springframework.stereotype.Service;

/**
 *
 * @author winnie
 */
@Service
public class CommonsEmailService implements IEmailService {

    private static final Logger LOG = Logger.getLogger(CommonsEmailService.class.getName());
    
    @Override
    public void echo() {
        System.out.println("Hello commons email!");
    }

    @Override
    public void sendMail(String content) {
        try {
            Email email = new SimpleEmail();
            email.setHostName("smtp.gmail.com");
            email.setSmtpPort(587);
            email.setAuthenticator(new DefaultAuthenticator("zhou.zhefu", "5642326"));
            email.setAuthentication("zhou.zhefu","5642326");
            email.setTLS(true);
            email.setFrom("zhou.zhefu@gmail.com");
            email.setSubject("TestMail");
            email.setMsg("This is a test mail ... :-)");
            email.addTo("jeff2033333@yahoo.com.sg");
            email.send();
        } catch (EmailException ex) {
            LOG.log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public void sendMail(EmailVO vo) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
